package agency.tango.materialintro.slice;

import agency.tango.materialintro.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class ShowDemoAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_show);
        initView();
    }

    private void initView() {
        jumpToAnotherPage(ResourceTable.Id_bt1, "ComponentDemoAbility");
        jumpToAnotherPage(ResourceTable.Id_bt2, "AbilitySliceDemoAbility");
        jumpToAnotherPage(ResourceTable.Id_bt3, "FractionDemoAbility");
    }

    private void jumpToAnotherPage(int id, String abilityName) {
        findComponentById(id).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent jumpIntent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("agency.tango.materialintro")
                        .withAbilityName("agency.tango.materialintro." + abilityName)
                        .build();
                jumpIntent.setOperation(operation);
                startAbility(jumpIntent);
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
